package com.pigdogbay.anagramsolver;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnShowListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class TipBox {
	TextView titleView, descView, indexView;
	Button _CancelBtn;
	static boolean _IsFirstTime = true;
	
	int index = 0;
	final static int MAX_INDEX = 9;
	int[] TitleIds = {R.string.tip_title_1,R.string.tip_title_2,R.string.tip_title_3,R.string.tip_title_4,R.string.tip_title_5,R.string.tip_title_6,R.string.tip_title_7,R.string.tip_title_8,R.string.tip_title_9};	
	int[] DescriptionIds = {R.string.tip_description_1,R.string.tip_description_2,R.string.tip_description_3,R.string.tip_description_4,R.string.tip_description_5,R.string.tip_description_6,R.string.tip_description_7,R.string.tip_description_8,R.string.tip_description_9};
	int[] IndexIds = {R.string.tip_index_1,R.string.tip_index_2,R.string.tip_index_3,R.string.tip_index_4,R.string.tip_index_5,R.string.tip_index_6,R.string.tip_index_7,R.string.tip_index_8,R.string.tip_index_9};

	public TipBox()
	{
		
	}
	
	public View create(Activity activity){
		View view = activity.getLayoutInflater().inflate(R.layout.tips_view, null);
		titleView = (TextView)view.findViewById(R.id.tips_title);
		descView = (TextView)view.findViewById(R.id.tips_description);
		indexView = (TextView)view.findViewById(R.id.tips_index);
		_CancelBtn = (Button)view.findViewById(R.id.tips_cancel_btn);
		((Button)view.findViewById(R.id.tips_next_btn)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				showNext();
			}
		});
		showNext();
		return view;
	}
	
	public void showNext(){
		titleView.setText(TitleIds[index]);
		descView.setText(DescriptionIds[index]);
		indexView.setText(IndexIds[index]);
		index++;
		if (index>=MAX_INDEX)
		{
			index = 0;
		}
		
	}
	
	public Button getCancelButton()
	{
		return _CancelBtn;
	}
	
	public static void show(Activity activity){
		
		final TipBox tipBox = new TipBox();
		final AlertDialog d = new AlertDialog.Builder(activity)
				.setView(tipBox.create(activity))
				.create();
		d.setOnShowListener(new OnShowListener() {
			@Override
			public void onShow(DialogInterface dialog) {
				Button b = tipBox.getCancelButton();
				b.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						d.dismiss();
					}
				});
			}
		});
		d.show();
		
	}
	
	public static void showFirstTimeOnly(Activity activity){
		if (_IsFirstTime)
		{
			show(activity);
			_IsFirstTime = false;
		}
	}
	
	
}
